﻿using System;
using Slf.Resolvers;

namespace Slf.Samples.CustomFactoryImplementation
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.ForegroundColor = ConsoleColor.Green;
      Console.Out.WriteLine("We plug in a single custom factory into SLF. Check out the 'MyFactory' class in the sample.\n\n");
      Console.ResetColor();

      //we are only dealing with a single factory, so wrap
      //wrap out custom factory in a SimpleFactoryResolver
      ILoggerFactory factory = new MyFactory();
      IFactoryResolver resolver = new SimpleFactoryResolver(factory);

      //plug in the resolver
      LoggerService.FactoryResolver = resolver;

      CreateLogEntries();
      Console.ReadLine();
    }

    private static void CreateLogEntries()
    {
      ILogger testLogger = LoggerService.GetLogger("Test");
      ILogger defaultLogger = LoggerService.GetLogger();
      ILogger loggerWithUnknownName1 = LoggerService.GetLogger("Foo");
      ILogger loggerWithUnknownName2 = LoggerService.GetLogger("Bar");


      testLogger.Info("Logging to test logger.");
      defaultLogger.Info("Logging to default logger.");

      //this method run
      loggerWithUnknownName1.Info("Logging to first logger with unknown name.");
      loggerWithUnknownName2.Info("Logging to second logger with unknown name.");
    }
  }
}